// 打字机效果
    window.onload = function() {
      var text = "欢迎登录";
      var i = 0;
      var p1 = document.getElementsByClassName('p1')[0];
      p1.innerHTML = "";
      function typeWriter() {
        if (i < text.length) {
          p1.innerHTML += "<b>" + text.charAt(i) + "</b>";
          i++;
          setTimeout(typeWriter, 150);
        }

      }
      typeWriter();

      // 密码可见切换
      var pwdInput = document.getElementById('password');
      var eye = document.getElementById('togglePwd');
      eye.onclick = function() {
        if (pwdInput.type === 'password') {
          pwdInput.type = 'text';
          eye.innerHTML = '🙈';
        } else {
          pwdInput.type = 'password';
          eye.innerHTML = '👁️';
        }
      };

      // 获取验证码倒计时
      var getCodeBtn = document.getElementById('getCodeBtn');
      var codeTimer = null;
      var codeTime = 60;
      getCodeBtn.onclick = function() {
        var phone = document.getElementById('phone').value.replace(/^\s+|\s+$/g, '');
        if (!/^1\d{10}$/.test(phone)) {
          alert('请输入正确的手机号！');
          return;
        }
        getCodeBtn.disabled = true;
        var left = codeTime;
        getCodeBtn.innerHTML = left + "s";
        codeTimer = setInterval(function() {
          left--;
          getCodeBtn.innerHTML = left + "s";
          if (left <= 0) {
            clearInterval(codeTimer);
            getCodeBtn.disabled = false;
            getCodeBtn.innerHTML = "获取验证码";
          }
        }, 1000);
        // 这里可以加AJAX请求验证码
        alert("验证码已发送到手机（模拟）");
      };

      // 登录校验与加载动画
      var loginBtn = document.getElementsByClassName('b1')[0];
      loginBtn.onclick = function(e) {
        e.preventDefault();
        var phone = document.getElementById('phone').value.replace(/^\s+|\s+$/g, '');
        var username = document.getElementById('username').value.replace(/^\s+|\s+$/g, '');
        var password = document.getElementById('password').value.replace(/^\s+|\s+$/g, '');
        var code = document.getElementById('code').value.replace(/^\s+|\s+$/g, '');
        if (!/^1\d{10}$/.test(phone)) {
          alert('请输入正确的手机号！');
          return false;
        }
        if (!username) {
          alert('账号不能为空！');
          return false;
        }
        if (!password) {
          alert('密码不能为空！');
          return false;
        }
        if (!/^\d{6}$/.test(code)) {
          alert('请输入6位数字验证码！');
          return false;
        }
        // 按钮加载动画
        loginBtn.innerHTML = '<span class="loader"></span>';
        setTimeout(function() {
          loginBtn.innerHTML = '<p class="p2" align="center">登录</p>';
          window.location.href = "智慧消防_1.html";
        }, 1200);
      };

      // 回车自动登录
      var inputs = document.getElementsByClassName('in');
      for (var j = 0; j < inputs.length; j++) {
        inputs[j].onkeydown = function(e) {
          e = e || window.event;
          if (e.keyCode === 13) {
            loginBtn.click();
          }
        };
      }
    };